<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
</head>

<body>
  <div>cuifan</div>
  <script>
    const xhr = new XMLHttpRequest(); // 创建对象
    xhr.open("get", "http://nodejs.cn/api/"); // 请求配置
    xhr.send(); // 发送请求

    xhr.onreadystatechange = function() {
      // 监听xhr.readyState的变化 0 1 2 3 4
      if (xhr.readyState === 4) {
        if (xhr.status >= 200 && xhr.status < 300) {
          console.log(xhr.response);
        }
      }
    };
  </script>
</body>

</html>